﻿using Kaiser.Modules.Hiner.Models.Consignee;
using Kaiser.Modules.Hiner.Models.Consignee.SearchModels;
using Kaiser.Modules.Hiner.Models.Order;
using Kaiser.Modules.Hiner.Models.Order.SearchModels;
using Kaiser.Modules.Hiner.Models.Supplier;
using Kaiser.Modules.Hiner.Models.Supplier.SearchModels;
using Kaiser.Modules.Hiner.Repositories;
using Kaiser.Repositories.iBatis.HINER;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Kaiser.Modules.Hiner.Models.Product.SearchModels;
using Kaiser.Models;
using Kaiser.Modules.Hiner.Models.Product;
using System.Collections.Generic;

namespace Kaiser.Modules.Test
{


    /// <summary>
    ///这是 OrderTest 的测试类，旨在
    ///包含所有 OrderTest 单元测试
    ///</summary>
    [TestClass()]
    [DeploymentItem(@"Kaiser.Site\Maps", "Maps")]
    [DeploymentItem(@"Kaiser.Site\Configs", "Configs")]
    public class OrderTest
    {

        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        public ConsigneeRepositorie ConsigneeRepositorieObject
        {
            get
            {
                return new ConsigneeRepositorie();

            }
        }

        public IOrderRepositorie RepositorieModel
        {
            get
            {
                return new OrderRepositorie();
            }
        }

        public IConsigneeRepositorie ConsigneeRepositorie
        {
            get
            {
                return new ConsigneeRepositorie();
            }
        }

        public IProductRepositorie ProductRepositorie
        {
            get
            {
                return new ProductRepositorie();
            }
        }

        public ISupplierRepositorie SupplierRepositorie
        {
            get
            {
                return new SupplierRepositorie();
            }
        }

        /// <summary>
        ///Order 构造函数 的测试
        ///</summary>
        [TestMethod()]
        public void OrderConstructorTest()
        {

            //    Assert.IncOConsigneeBase: 实现用来验证目标的代码");
        }

        #region Consignee 测试
        /// <summary>
        ///Delete 的测试
        ///</summary>
        [TestMethod()]
        public void DeleteConsigneeTest()
        {
            try
            {
                Consignee target = new Consignee(ConsigneeRepositorie); 
                object primaryId = "1a2182af-8969-424b-ae11-0db9e0672714"; 
                target.Delete(primaryId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }

        /// <summary>
        ///Get 的测试
        ///</summary>
        [TestMethod()]
        public void GetConsigneeTest()
        {
            try
            {
                Consignee target = new Consignee(ConsigneeRepositorie); 
                var primaryId = "1a2182af-8969-424b-ae11-0db9e0672714"; 
                target.Get(primaryId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }

        /// <summary>
        ///Insert 的测试
        ///</summary>
        [TestMethod()]
        public void InsertConsigneeTest()
        {
            try
            {
                for (int i = 0; i < 15; i++)
                {
                    Consignee target = new Consignee(ConsigneeRepositorie); 
                    var model = new ConsigneeBase();
                    model.ConsigneeId = Guid.NewGuid().ToString();
                    model.ConsigneeName = "Test00001" + i.ToString();
                    model.ConsigneeTel = "123";
                    model.CreateUserFullName = "0000111";
                    model.CreateDateTime = DateTime.Now;
                    model.CreateUserFullName = "姓名";
                    model.CreateUserName = "username";
                    model.LastModifyDateTime = DateTime.Now;
                    model.LastModifyUserFullName = "姓名1";
                    model.LastModifyUserName = "姓名1";
                    model.ConsigneeAddress = "条款";
                    model.ConsigneeCode = "姓名2";
                    model.ConsigneeFax = "123213412341231";

                    target.Insert(model);
                }
            }
            catch (Exception)
            {
                throw;
            }

            Assert.IsFalse(false);
        }

        /// <summary>
        ///SearchOrder 的测试
        ///</summary>
        [TestMethod()]
        public void SearchConsigneeTest()
        {
            try
            {
                Consignee target = new Consignee(ConsigneeRepositorie); 
                var search = new ConsigneeSearch(); 
                PagingInfo pageinfo = new PagingInfo(); 
                //IList<OrderBase> expected = null; 
                DataGrid<ConsigneeBase> actual;
                search.ConsigneeId = "123";
                pageinfo.Size = 10;
                pageinfo.Index = 0;
                pageinfo.SkipTop = 5;
                actual = target.SearchConsignee(search, pageinfo);

                //Assert.AreEqual(expected, actual);
                Assert.Inconclusive("验证此测试方法的正确性。");
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        ///Update 的测试
        ///</summary>
        [TestMethod()]
        public void UpdateConsigneeTest()
        {
            try
            {
                Consignee target = new Consignee(ConsigneeRepositorie); 
                var model = new ConsigneeBase();
                var primaryId = "1a2182af-8969-424b-ae11-0db9e0672714"; 
                model = target.Get(primaryId);
                model.ConsigneeName = "Test0003";
                target.Update(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }
        #endregion

        #region order 测试
        /// <summary>
        ///Delete 的测试
        ///</summary>
        [TestMethod()]
        public void DeleteTest()
        {
            try
            {
                Order target = new Order(RepositorieModel); 
                object primaryId = "b02768f4-f9dc-4150-8d39-662b9fd7097c"; 
                target.Delete(primaryId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }

        /// <summary>
        ///Get 的测试
        ///</summary>
        [TestMethod()]
        public void GetTest()
        {
            try
            {
                Order target = new Order(RepositorieModel); 
                var primaryId = "062cec45-7027-487c-b4ae-a1f501850401"; 
                var obj = target.Get(primaryId);

                Assert.IsNotNull(obj);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //   Assert.Inconclusive("无法验证不返回值的方法。");
        }

        /// <summary>
        ///Insert 的测试
        ///</summary>
        [TestMethod()]
        public void InsertTest()
        {
            try
            {
                for (int i = 0; i < 15; i++)
                {
                    Order target = new Order(RepositorieModel); 
                    var model = new OrderBase();
                    model.OrderId = Guid.NewGuid().ToString();
                    model.OrderNo = "Test00001" + i.ToString();
                    model.SupplierId = "123";

                    model.CreateDateTime = DateTime.Now;
                    model.CreateUserFullName = "姓名";
                    model.CreateUserName = "username";
                    model.LastModifyDateTime = DateTime.Now;
                    model.LastModifyUserFullName = "姓名1";
                    model.LastModifyUserName = "姓名1";
                    model.OrderClause = "条款";
                    model.OrderContacts = "姓名2";
                    model.OrderContactsWay = "123213412341231";
                    model.OrderDate = DateTime.Now;
                    model.OrderDeliveryDate = DateTime.Now;
                    model.OrderNo = "123456";
                    model.OrderOperatime = DateTime.Now;
                    model.OrderDetailList = new List<OrderDetail>();
                    model.OrderDetailList.Add(new OrderDetail()
                    {
                        Quantity = 2,
                        ProductActualPrice = 240,
                    });
                    target.Insert(model);
                }
            }
            catch (Exception)
            {
                throw;
            }

            Assert.IsFalse(false);
        }

        /// <summary>
        ///OrderDelivery 的测试
        ///</summary>
       
        /// <summary>
        ///SearchOrder 的测试
        ///</summary>
        [TestMethod()]
        public void SearchOrderTest()
        {
            try
            {
                Order target = new Order(RepositorieModel); 
                var search = new OrderSearch(); 
                PagingInfo pageinfo = new PagingInfo(); 
                //IList<OrderBase> expected = null; 
                DataGrid<OrderBase> actual;
                search.SupplierId = "123";
                pageinfo.Size = 10;
                pageinfo.Index = 0;
                pageinfo.SkipTop = 5;
                actual = target.SearchOrder(search, pageinfo);

                //Assert.AreEqual(expected, actual);
                Assert.Inconclusive("验证此测试方法的正确性。");
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        ///Update 的测试
        ///</summary>
        [TestMethod()]
        public void UpdateTest()
        {
            try
            {
                Order target = new Order(RepositorieModel); 
                var model = new OrderBase();
                var primaryId = "b02768f4-f9dc-4150-8d39-662b9fd7097c"; 
                model = target.Get(primaryId);
                model.OrderId = "b02768f4-f9dc-4150-8d39-662b9fd7097c";
                model.OrderNo = "Test0003";
                model.CreateDateTime = DateTime.Now;
                model.LastModifyDateTime = DateTime.Now;
                model.OrderDeliveryDate = DateTime.Now;
                model.OrderDate = DateTime.Now;
                model.OrderOperatime = DateTime.Now;
                model.OrderDetailList = new List<OrderDetail>();
                model.OrderDetailList.Add(new OrderDetail()
                {
                    Quantity = 2,
                    ProductActualPrice = 240,
                });
                target.Update(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }

        /// <summary>
        /// 订单交付测试
        /// </summary>
        [TestMethod()]
        public void OrderDeliveryTest()
        {
            var target = new Order(RepositorieModel); 
            string orderId = "18bc71eb-5679-47e4-ab09-0aaad534ffcb";
            bool isReplay = false;
            try
            {
                isReplay = target.OrderDelivery(orderId);
            }
            catch (Exception)
            {
                
                throw;
            }
            Assert.Inconclusive("验证此测试方法的正确性。");
        }

        /// <summary>
        /// 订单确认测试
        /// </summary>
        [TestMethod()]
        public void OrderConfirmTest()
        {
            var target = new Order(RepositorieModel); 
            string orderId = "18bc71eb-5679-47e4-ab09-0aaad534ffcb";
            bool isReplay = false;
            try
            {
                isReplay = target.OrderConfirm(orderId);
            }
            catch (Exception)
            {
                throw;
            }
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
        #endregion

        #region Product 测试
        /// <summary>
        ///Delete 的测试
        ///</summary>
        [TestMethod()]
        public void DeleteProductTest()
        {
            try
            {
                var target = new Product(ProductRepositorie); 
                object primaryId = "060be211-b732-4902-b047-6ad48160d798"; 
                target.Delete(primaryId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }

        /// <summary>
        ///Get 的测试
        ///</summary>
        [TestMethod()]
        public void GetProductTest()
        {
            try
            {
                var target = new Product(ProductRepositorie); 
                var primaryId = "3e486c48-cacf-4a2c-bdb4-a20900cdb07e"; 
                target.Get(primaryId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }

        /// <summary>
        ///Insert 的测试
        ///</summary>
        [TestMethod()]
        public void InsertProductTest()
        {
            try
            {
                for (int i = 0; i < 15; i++)
                {
                    var target = new Product(ProductRepositorie); 
                    var model = new ProductBase();
                    model.ProductId = Guid.NewGuid().ToString();
                    model.ProductName = "Test00001" + i.ToString();
                    model.ProductOERef = "123";
                    model.CreateUserFullName = "123";
                    model.CreateDateTime = DateTime.Now;
                    model.CreateUserFullName = "姓名";
                    model.CreateUserName = "username";
                    model.LastModifyDateTime = DateTime.Now;
                    model.LastModifyUserFullName = "姓名1";
                    model.LastModifyUserName = "姓名1";
                    model.ProductPrice = 12313;
                    model.ProductSize = "姓名2";
                    model.SupplierCode = "123213412341231";
                    model.ProductCarModel = "123123";
                    model.ProductDepict = "asdsad";
                    model.ProductDesc = "1";
                    model.ProductHDECode = "asdafsdf";
                    model.ProductHinerCode = "asdasgfsas";
                    model.ProductImgUrl = "asddgfsda";
                    model.SupplierName = "1";
                    model.ProductCount = 123;
                    target.Insert(model);
                }
            }
            catch (Exception)
            {
                throw;
            }

            Assert.IsFalse(false);
        }

        /// <summary>
        ///SearchOrder 的测试
        ///</summary>
        [TestMethod()]
        public void SearcheProductTest()
        {
            try
            {
                Product target = new Product(ProductRepositorie); 
                var search = new ProductSearch(); 
                PagingInfo pageinfo = new PagingInfo(); 
                //IList<OrderBase> expected = null; 
                DataGrid<ProductBase> actual;
                search.ProductHinerCode = "asdasgfsas";
                pageinfo.Size = 10;
                pageinfo.Index = 0;
                pageinfo.SkipTop = 5;
                actual = target.SearchProduct(search, pageinfo);

                //Assert.AreEqual(expected, actual);
                Assert.Inconclusive("验证此测试方法的正确性。");
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        ///Update 的测试
        ///</summary>
        [TestMethod()]
        public void UpdateProductTest()
        {
            try
            {
                var target = new Product(ProductRepositorie); 
                var model = new ProductBase();
                var primaryId = "060be211-b732-4902-b047-6ad48160d798"; 
                model = target.Get(primaryId);
                model.CreateUserFullName = "Test0003";
                target.Update(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }

        /// <summary>
        /// VaidHinerCode的测试
        /// </summary>
        /// <param name="code"></param>
        /// <param name="id"></param>
        [TestMethod()]
        public void VaidHinerCodeTest()
        {
            var target = new Product(ProductRepositorie); 
            string code = "231231";
            string id = "3e486c48-cacf-4a2c-bdb4-a20900cdb07e";
            bool isReplay = false;
            isReplay = target.VaidHinerCode(code, id);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }

        /// <summary>
        /// ValidHDECodeTest的测试
        /// </summary>
        [TestMethod()]
        public void ValidHDECodeTest()
        {
            var target = new Product(ProductRepositorie); 
            string code = "1231231";
            string id = "3e486c48-cacf-4a2c-bdb4-a20900cdb07e";
            bool isReplay = false;
            isReplay = target.ValidHDECode(code, id);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }

       
        #endregion

        #region Supplier 测试
        /// <summary>
        ///Delete 的测试
        ///</summary>
        [TestMethod()]
        public void DeleteSupplierTest()
        {
            try
            {
                Supplier target = new Supplier(SupplierRepositorie); 
                object primaryId = "05c4f7ef-9e17-4560-b77a-8b6692b164c5"; 
                target.Delete(primaryId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }

        /// <summary>
        ///Get 的测试
        ///</summary>
        [TestMethod()]
        public void GetSupplierTest()
        {
            try
            {
                Supplier target = new Supplier(SupplierRepositorie); 
                var primaryId = "12160a0f-c1f3-496f-96a0-0a7c4e24e66b"; 
                target.Get(primaryId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }

        /// <summary>
        ///Insert 的测试
        ///</summary>
        [TestMethod()]
        public void InsertSupplierTest()
        {
            try
            {
                for (int i = 0; i < 15; i++)
                {
                    Supplier target = new Supplier(SupplierRepositorie); 
                    var model = new SupplierBase();
                    model.SupplierId = Guid.NewGuid().ToString();
                    model.SupplierName = "Test00001" + i.ToString();
                    model.SupplierAddress = "123";
                    model.CreateUserFullName = "123";
                    model.CreateDateTime = DateTime.Now;
                    model.CreateUserFullName = "姓名";
                    model.CreateUserName = "username";
                    model.LastModifyDateTime = DateTime.Now;
                    model.LastModifyUserFullName = "姓名1";
                    model.LastModifyUserName = "姓名1";
                    model.SupplierDesc = "a";
                    model.SupplierClause = "1";
                    model.SupplierCode = "123213412341231";
                    model.SupplierContactWay = "123123";
                    model.SupplierLinkManCode = "asdsad";
                    model.SupplierLinkManName = "1";
                    target.Insert(model);
                }
            }
            catch (Exception)
            {
                throw;
            }

            Assert.IsFalse(false);
        }

        /// <summary>
        ///SearchOrder 的测试
        ///</summary>
        [TestMethod()]
        public void SearchSupplierTest()
        {
            try
            {
                Supplier target = new Supplier(SupplierRepositorie); 
                var search = new SupplierSearch(); 
                PagingInfo pageinfo = new PagingInfo(); 
                //IList<OrderBase> expected = null; 
                DataGrid<SupplierOrder> actual;
                search.CreateUserName = "123";
                pageinfo.Size = 10;
                pageinfo.Index = 0;
                pageinfo.SkipTop = 5;
                actual = target.SearchSupplier(search, pageinfo);

                //Assert.AreEqual(expected, actual);
                Assert.Inconclusive("验证此测试方法的正确性。");
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        ///Update 的测试
        ///</summary>
        [TestMethod()]
        public void UpdateSupplierTest()
        {
            try
            {
                Supplier target = new Supplier(SupplierRepositorie); 
                var model = new SupplierBase();
                var primaryId = "05c4f7ef-9e17-4560-b77a-8b6692b164c5"; 
                model = target.Get(primaryId);
                model.CreateUserFullName = "Test0003";
                target.Update(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }
        #endregion

        #region 上传测试


        /// <summary>
        /// 删除
        /// </summary>
        [TestMethod()]
        public void DeleteAttachment()
        {
            try
            {
                var target = new Product(ProductRepositorie); 
                string primaryId = "1";
                target.DeleteAttachment(primaryId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }



        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="model"></param>
        public void InsertAttachment()
        {
            try
            {
                var target = new Product(ProductRepositorie); 
                Attachment model = new Attachment();
                model.Attach_ContentType = "image/pjpeg";
                model.Attach_CreateTime = DateTime.Now;
                model.Attach_FileName = "3082e301f62bf1e6fe11dc8ab3487193.jpg";
                model.Attach_ObjectID = "e4c8a41f-9869-46eb-9ae2-a1ef018199e6";
                model.Attach_ObjectModule = "UploadFile/" + DateTime.Now.ToString("yyyy-MM-dd") + model.Attach_ObjectID + model.Attach_FileName;
                model.Attach_Path = "";
                model.Attach_Size = 2046;
                target.InsertAttachment(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        public Attachment GetAttachment(string pid)
        {
            try
            {
                var target = new Product(ProductRepositorie); 
                string primaryId = "1";
                return target.GetAttachment(primaryId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
    }
}
